﻿// <com.woyouqiu.Copyright>
// --------------------------------------------------------------
// <copyright>上海有求网络科技有限公司 2015</copyright>
// <Solution>Vecen.BangChuang</Solution>
// <Project>Vecen.BangChuang.Tests</Project>
// <FileName>ServiceCollectionRegistrar.cs</FileName>
// <CreateTime>2017-04-26 18:04</CreateTime>
// <Author>何苗</Author>
// <Email>hemiao@woyouqiu.com</Email>
// <log date="2017-04-26 18:04" version="00001">创建</log>
// --------------------------------------------------------------
// </com.woyouqiu.Copyright>

using System;
using Abp.Dependency;
using Castle.MicroKernel.Registration;
using Castle.Windsor.MsDependencyInjection;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Vecen.BangChuang.EntityFrameworkCore;
using Vecen.BangChuang.Identity;

namespace Vecen.BangChuang.Tests.DependencyInjection {
    public static class ServiceCollectionRegistrar {
        public static void Register(IIocManager iocManager) {
            var services = new ServiceCollection();

            IdentityRegistrar.Register(services);

            services.AddEntityFrameworkInMemoryDatabase();

            var serviceProvider = WindsorRegistrationHelper.CreateServiceProvider(iocManager.IocContainer, services);

            var builder = new DbContextOptionsBuilder<BangChuangDbContext>();
            builder.UseInMemoryDatabase(Guid.NewGuid().ToString()).UseInternalServiceProvider(serviceProvider);

            iocManager.IocContainer.Register(Component.For<DbContextOptions<BangChuangDbContext>>()
                .Instance(builder.Options)
                .LifestyleSingleton());
        }
    }
}